<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Prex Sample Applications</title>
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  <meta name="keywords" content="Prex, embedded, real-time, operating system, RTOS, open source, free">
  <meta name="author" content="Kohsuke Ohtani">
  <link rel="stylesheet" type="text/css" href="../default.css" media="screen">
  <link rel="stylesheet" type="text/css" href="../print.css" media="print">
</head>
<body>
<div id="top">
</div>
<div id="middle">

<table id="content" cellpadding="0" cellspacing="0">
  <tbody>

    <tr>
      <td id="header" colspan="2" valign="top">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td id="logo">
            <a href="http://prex.sourceforge.net/">
            <img alt="Prex logo" src="../img/logo.gif" border="0"
            style="width: 250px; height: 54px;"></a>
          </td>
          <td id="brief" align="right" valign="bottom">
            An Open Source, Royalty-free,<br>
	    Real-time Operating System
          </td>
        </tr>
        </table>
      </td>
    </tr>

    <tr>
      <td id="directory" style="vertical-align: top;">
      <a href="http://prex.sourceforge.net/">Prex Home</a> >
      <a href="index.html">Document Index</a> >
      Sample Applications
    </tr>
    <tr><td class="pad" colspan="2" style="vertical-align: top;"></td></tr>

    <tr>
      <td id="doc" style="vertical-align: top;">
      <h1>Prex Sample Applications</h1>

<i>Version 0.8, 2008/09/09</i>

<h3>Table of Contents</h3>
<ul>
  <li><a href="#intro">Introduction</a></li>
  <li><a href="#hello">Hello World</a></li>
  <li><a href="#alarm">Alarm Timer</a></li>
  <li><a href="#balls">Moving Balls</a></li>
  <li><a href="#bench">Thread Benchmark</a></li>
  <li><a href="#ipc">IPC Transmission</a></li>
  <li><a href="#task">Task Creation</a></li>
  <li><a href="#thread">Thread Creation</a></li>
  <li><a href="#mutex">Mutex</a></li>
  <li><a href="#semaphore">Semaphore</a></li>
  <li><a href="#cpu">CPU Voltage Monitor</a></li>
<!--
  <li><a href="#tetris">Tetris</a></li>
-->
</ul>
<br>

<h2 id="intro">Introduction</h2>
<p>
Prex includes a number of sample programs for using Prex application interface.
The source code for these programs are generally found in /usr/sample
directory of the Prex distribution.
</p>
<p>
This document describes the purpose and the screenshot for each sample program.
</p>

<h2 id="hello">Hello World</h2>
<ul>
<li>Task Type: UNIX Process</li>
<li>Source Code Directory: /usr/sample/hello</li>
<li>Description: A simple program to print "Hello World!"</li>
</ul>

<pre class="terminal">
[prex:/boot]# hello
Hello World!
[prex:/boot]#
</pre>


<h2 id="alarm">Alarm Timer</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/alarm</li>
<li>Description: A sample program to install an alarm handler and to program an alarm
timer.
</ul>

<pre class="terminal">
Alarm sample program
Start alarm timer
Ring! count=1 time=1000 msec
Ring! count=2 time=1200 msec
Ring! count=3 time=1600 msec
Ring! count=4 time=2200 msec
Ring! count=5 time=3000 msec
Ring! count=6 time=4000 msec
Ring! count=7 time=5200 msec
Ring! count=8 time=6600 msec
Ring! count=9 time=8200 msec
Ring! count=10 time=10000 msec
End...
</pre>


<h2 id="balls">Moving Balls</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/balls</li>
<li>Description: A program to create many threads.
Each thread displays one ball and moves it in the screen.</li>
</ul>

<pre class="terminal">
                                        *                            *
                           *
                *
                                                              *
                                                         *

                                                       *  *


                                                                *           *
   *                                                        **

                *                  *                     *
                                                                    *    *
                    *
      *
                                       *

                             *                                 *

              *
                       *
                 *    *   *                           *
</pre>


<h2 id="bench">Thread Benchmark</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/bench</li>
<li>Description: A benchmark program for running many threads</li>
</ul>

<pre class="terminal">
Benchmark to create/terminate 100000 threads
Complete. The score is 612 msec (612 ticks).
</pre>


<h2 id="ipc">IPC Transmission</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/ipc</li>
<li>Description: A sample program for IPC message transmission</li>
</ul>

<pre class="terminal">
IPC sample program
Client is started
server: Received "Hello!"
client: Received "Hi."
server: Received "This is a client task."
client: Received "OK."
server: Received "Who are you?"
client: Received "OK."
server: Received "How are you?"
client: Received "OK."
server: Received "...."
client: Received "OK."
server: Received "Bye!"
client: Received "Bye."
server: Received "Exit"
client: Received "OK."
Exit client task...
End...
</pre>


<h2 id="task">Task Creation</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/task</li>
<li>Description: A sample program to run tasks</li>
</ul>

<pre class="terminal">
Task sample program
Task 8000abc4: Hey, Yo!
Task 8000ae24: Hey, Yo!
Task 80027714: Hey, Yo!
Task 80027c44: Hey, Yo!
Task 80027ea4: Hey, Yo!
Task 80037744: Hey, Yo!
Task 80037cb4: Hey, Yo!
Task 80037f14: Hey, Yo!
Task 800477a4: Hey, Yo!
Task 80047d14: Hey, Yo!
Task 8000abc4: Bye!
Task 8000ae24: Bye!
Task 80027714: Bye!
Task 80027c44: Bye!
Task 80027ea4: Bye!
Task 80037744: Bye!
Task 80037cb4: Bye!
Task 80037f14: Bye!
Task 800477a4: Bye!
Task 80047d14: Bye!
</pre>


<h2 id="thread">Thread Creation</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/thread</li>
<li>Description: A sample program to create three threads</li>
</ul>

<pre class="terminal">
Thread sample program

thread A is starting
A
thread B is starting
B
thread C is starting
CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBCCCCCCCCCCCCCCAAA
</pre>


<h2 id="mutex">Mutex</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/mutex</li>
<li>Description: A sample program for mutex with priority inheritance</li>
</ul>
<pre class="raw">
Senario:

 This sample shows how the mutex priority is changed when three different threads
 lock two mutexes at same time.

 The priority of each thread are as follows:
    Thread1 - priority 100 (highest)
    Thread2 - priority 101
    Thread3 - priority 102

Thread priority and state are changed as follows:

   Action                    Thread 1  Thread 2  Thread 3  Mutex A  Mutex B
   ------------------------  --------  --------  --------  -------  -------
1) Thread 3 locks mutex A    susp/100  susp/101  run /102  owner=3
2) Thread 2 locks mutex B    susp/100  run /101  run /102  owner=3  owner=2
3) Thread 2 locks mutex A    susp/100  wait/101  run /101* owner=3  owner=2
4) Thread 1 locks mutex B    wait/100  wait/100* run /100* owner=3  owner=2
5) Thread 3 unlocks mutex A  wait/100  run /100  run /102* owner=2* owner=2
6) Thread 2 unlocks mutex B  run /100* run /100  run /102  owner=2  owner=1*
7) Thread 2 unlocks mutex A  run /100  run /100  run /102           owner=1
8) Thread 1 unlocks mutex B  wait/100  run /101  run /102
</pre>

<pre class="terminal">
Mutex sample program
th_1: prio=100
th_2: prio=101
th_3: prio=102
thread_3: start
thread_3: 1) lock A
th_1: prio=100
th_2: prio=101
th_3: prio=102
thread_2: starting
thread_2: 2) lock B
th_1: prio=100
th_2: prio=100
th_2: prio=101
th_3: prio=102
thread_2: 3) lock A
thread_3: running-1
th_1: prio=100
th_2: prio=101
th_3: prio=101
thread_1: starting
thread_1: 4) lock B
thread_3: running-2
th_1: prio=100
th_2: prio=100
</pre>


<h2 id="semaphore">Semaphore</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/sem</li>
<li>Description: A sample program for semaphore.
This sample demonstrates that 10 threads try to aquire
one semaphore which has initial sempaphore count = 3.
</li>
</ul>

<pre class="terminal">
Semaphore sample program
Start thread=8000abf4
Start thread=8001e014
Start thread=8001e404
Start thread=8001e7f4
Start thread=8001ebe4
Start thread=8001f014
Start thread=8001f404
Start thread=8001f7f4
Start thread=8001fbe4
Start thread=80020014
Running thread=8000abf4
Running thread=8001e014
Running thread=8001e404
Running thread=8001e7f4
End thread=8000abf4
Running thread=8001ebe4
End thread=8001e014
Running thread=8001f014
End thread=8001e404
Running thread=8001f404
End thread=8001e7f4
Running thread=8001f7f4
End thread=8001ebe4
Running thread=8001fbe4
</pre>


<h2 id="cpu">CPU Voltage Monitor</h2>

<ul>
<li>Task Type: Real-time Task</li>
<li>Source Code Directory: /usr/sample/cpumon</li>
<li>Description: CPU voltage monitoring program</li>
</ul>

<pre class="terminal">
CPU voltage monitor
Speed:  600MHz  0|********------------|100
Power:  956mV   0|*************-------|100
</pre>



<!--

<h2 id="tetris">Tetris</h2>

<ul>
<li>Task Type: UNIX Process</li>
<li>Source Code Directory: /usr/sample/tetris</li>
<li>Description: Tetris game ported from BSD</li>
</ul>

<p>
</p>

<pre class="terminal">
55                         XX                    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX            XX      XX
                           XX            XXXX    XX
                           XX              XX    XX
                           XX                    XX
                           XX                    XX
                           XX                    XX
                           XX    XX              XX
                           XX    XX  XXXXXXXXXX  XX
                           XX    XX  XX      XXXXXX
                           XX  XXXX  XX    XXXXXXXX
                           XXXXXXXX  XXXX    XXXXXX
                           XXXXXXXXXXXXXXXXXXXXXXXX


  j - left   k - rotate   l - right   &lt;space&gt; - drop   p - pause   q - quit
</pre>

-->



      </td>
    </tr>
    <tr>
      <td id="footer" colspan="2" style="vertical-align: top;">
        <a href="http://sourceforge.net">
        <img src="http://sourceforge.net/sflogo.php?group_id=132028&amp;type=1"
        alt="SourceForge.net Logo" border="0" height="31" width="88"></a><br>
        Copyright&copy; 2008 Kohsuke Ohtani
      </td>
    </tr>

  </tbody>
</table>

</div>
<div id="bottom"></div>

</body>
</html>
